export const handleLink = (_link) => {
  if (!_link) return;
  window.open(_link, "noopener", "noreferrer");
};
//正确错误提示
import { ElMessage } from "element-plus";
export const tipMessage = (data) => {
  if (data.success_data.length) {
    ElMessage.success({
      showClose: true,
      dangerouslyUseHTMLString: true,
      message: data.success_data.join("<br/>"),
    });
  }
  if (data.fail_data.length) {
    ElMessage.error({
      showClose: true,
      dangerouslyUseHTMLString: true,
      message: data.fail_data.join("<br/>"),
    });
  }
};

/**
 * 获取选中行-导出
 * @param {*} ref
 * @param {*} key
 * @returns
 */
export const getTableSelectRow = (ref, key = "id") => {
  let records = ref?.$table?.getCheckboxRecords() || [];
  let arr = records?.map((item) => item[key]);
  if (arr.length) {
    return { [key]: arr };
  } else {
    return ref.getQueryForm();
  }
};

/**
 * 获取选中行-导出-旧
 * @param {*} ref
 * @param {*} key
 * @returns
 */
export const getTableSelectRowOld = (ref, params, key = "id") => {
  let records = ref?.getCheckboxRecords() || [];
  let arr = records?.map((item) => item[key]);
  if (arr.length) {
    return { [key]: arr };
  } else {
    return params;
  }
};
/**
 * 获取选中行
 * @param {*} ref
 * @param {*} key
 * @returns
 */
export const getTableSelect = (ref, key = "id") => {
  let records = ref?.$table?.getCheckboxRecords() || [];
  let arr = records?.map((item) => item[key]);
  return arr;
};